//
//  GYBuyListCell.m
//  GYDemo
//
//  Created by Mrzhang on 2018/3/29.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "GYBuyListCell.h"
#import "Head.h"


@interface GYBuyListCell ()<GCAdaptLabelDelegate>
@property (nonatomic,strong) GCAdaptLabel *nameLB;
@property (nonatomic,strong) GCAdaptLabel *typeLB;
@property (nonatomic,strong) NSArray *types;
@property (nonatomic,strong) GCAdaptLabel *priceLB;
@property (nonatomic,strong) GCAdaptLabel *areaLB;
@property (nonatomic,strong) UILabel *dealCountLB;
@property (nonatomic,strong) UILabel *dateLB;
@end

@implementation GYBuyListCell

#pragma mark - getter and setter

-(UIButton *)offerBtn
{
    if (!_offerBtn) {
        _offerBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        _offerBtn.backgroundColor=Main_Color_Blue;
        [_offerBtn setTitle:@"我要供货" forState:UIControlStateNormal];
        _offerBtn.titleLabel.font=SYSTEMFONT(15);
        _offerBtn.frame=WFCGRectMake(273, 22, 89, 34);
        [WFFunctions WFUIaddbordertoView:_offerBtn radius:17 width:0 color:[UIColor clearColor]];
        
        
        UIColor *bottomrightColor = HEXCOLOR(@"#457AE8");
        UIColor *topleftColor =HEXCOLOR(@"#5F96FF");
        _offerBtn.backgroundColor =[WFFunctions GradualChangeColor:@[topleftColor,bottomrightColor] ViewSize:WFCGSizeMake(89, 34) gradientType:GradientTypeLeftToRight];

    }
    return _offerBtn;
}
-(GCAdaptLabel *)nameLB
{
    if (!_nameLB) {
        _nameLB = [[GCAdaptLabel alloc]initWithMaxWidth:WFCGFloatX(145.5)];
        _nameLB.x = WFCGFloatX(12);
        _nameLB.y = WFCGFloatY(14);
        _nameLB.width = WFCGFloatX(145.5);
        _nameLB.height = WFCGFloatY(21);
        _nameLB.font = SYSTEMFONT(18);
        _nameLB.textColor = Main_Color_Black;
        _nameLB.delegate = self;
    }
    return _nameLB;
}
-(GCAdaptLabel *)typeLB
{
    if (!_typeLB) {
        _typeLB = [[GCAdaptLabel alloc]initWithMaxWidth:WFCGFloatX(60)];
        _typeLB.x = WFCGFloatX(158);
        _typeLB.y = WFCGFloatY(14);
        _typeLB.width = WFCGFloatX(145.5);
        _typeLB.height = WFCGFloatY(13);
        _typeLB.font = SYSTEMFONT(10);
        _typeLB.textColor = Main_Color_Black;
        [WFFunctions WFUIaddbordertoView:_typeLB radius:WFCGFloatY(3) width:0.7f color:Main_Color_Black];
        _typeLB.delegate = self;
    }
    return _typeLB;
}
-(GCAdaptLabel *)priceLB
{
    if (!_priceLB) {
        _priceLB = [[GCAdaptLabel alloc]initWithMaxWidth:WFCGFloatX(140)];
        _priceLB.x = WFCGFloatX(12);
        _priceLB.y = WFCGFloatY(78);
        _priceLB.width = WFCGFloatX(66.5);
        _priceLB.height = WFCGFloatY(20);
        _priceLB.textColor = Main_Color_Red;
        _priceLB.font = SYSTEMFONT(15);
        _priceLB.delegate = self;
    }
    return _priceLB;
}
-(GCAdaptLabel *)areaLB
{
    if (!_areaLB) {
        _areaLB = [[GCAdaptLabel alloc]initWithMaxWidth:WFCGFloatX(145)];
        _areaLB.x = WFCGFloatX(11);
        _areaLB.y = WFCGFloatY(44);
        _areaLB.width = WFCGFloatX(145);
        _areaLB.height = WFCGFloatY(16.5);
        _areaLB.textColor = HEXCOLOR(@"#666666");
        _areaLB.font = SYSTEMFONT(12);
       // _areaLB.backgroundColor = Main_Color_BG;
        
        _areaLB.delegate = self;
    }
    return _areaLB;
}
-(UILabel *)dealCountLB
{
    if (!_dealCountLB) {
        _dealCountLB = [[UILabel alloc]init];
        _dealCountLB.x = WFCGFloatX(160);
        _dealCountLB.y = WFCGFloatY(44);
        _dealCountLB.width = WFCGFloatX(220);
        _dealCountLB.height = WFCGFloatY(16.5);
        _dealCountLB.textColor = HEXCOLOR(@"#666666");
        _dealCountLB.font = SYSTEMFONT(13);
    }
    return _dealCountLB;
}

-(UILabel *)dateLB
{
    if (!_dateLB) {
        _dateLB = [[UILabel alloc]init];
        _dateLB.x = WFCGFloatX(375-142);
        _dateLB.y = WFCGFloatY(84);
        _dateLB.width = WFCGFloatX(130);
        _dateLB.height = WFCGFloatY(15);
        _dateLB.textColor = Main_Color_LightGray;
        _dateLB.font = SYSTEMFONT(11);
        _dateLB.textAlignment = NSTextAlignmentRight;
      //  [WFFunctions WFUIaddbordertoView:_dateLB radius:WFCGFloatY(3) width:0.5f color:Main_Color_LightGray];
    }
    return _dateLB;
}
-(void)setModel:(GYHomeBuyProductInfoModel *)model
{
    _model = model;
    _nameLB.text = _model.name;
    _typeLB.text = [NSString stringWithFormat:@" %@ ",_model.mark];

    NSString *unit = @"";
    NSString *priceUnit = !unit?[NSString stringWithFormat:@"/%@",unit]:@"";
    NSString *prices = [NSString stringWithFormat:@"%ld - %ld元",_model.minprice,_model.maxprice];
    NSString *price = [NSString stringWithFormat:@"%@%@",prices,priceUnit];
    _priceLB.text = price;

    NSString *area = [NSString stringWithFormat:@" %@",model.address];
    _areaLB.text = area;

    NSString *dealCount = [NSString stringWithFormat:@"求购数量：%ld",(long)_model.count];
    _dealCountLB.text = dealCount;
    _dateLB.text = [NSString stringWithFormat:@"发布日期:%@",_model.time];
}
#pragma mark - event
#pragma mark - method
+(CGFloat)finalHeight
{
    return WFCGFloatY(91);
}
#pragma mark - life

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self.contentView addSubview:self.nameLB];
        [self.contentView addSubview:self.typeLB];
        [self.contentView addSubview:self.priceLB];
        [self.contentView addSubview:self.areaLB];
        [self.contentView addSubview:self.dealCountLB];
        [self.contentView addSubview:self.dateLB];
        [self.contentView addSubview:self.offerBtn];
    }
    return self;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}
#pragma mark - delegate
-(void)callback:(id)sender
{
    _typeLB.x = _nameLB.right + WFCGFloatX(5);
    _typeLB.centerY = _nameLB.centerY;
    //_areaLB.x = _priceLB.right + WFCGFloatX(6);
    _dealCountLB.x=_areaLB.right+WFCGFloatX(6);
   // [WFFunctions WFUIaddbordertoView:_areaLB radius:WFCGFloatY(3) width:0.0f color:nil];
}

@end
